/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package cz.muni.fi.pv168.reminder.swing.workers;

import cz.muni.fi.pv168.reminder.entities.Task;
import cz.muni.fi.pv168.reminder.managers.TaskManager;
import cz.muni.fi.pv168.reminder.managers.implementation.TaskManagerImpl;
import cz.muni.fi.pv168.reminder.swing.FrameMainWindow;
import javax.swing.SwingWorker;

/**
 *
 * @author Adic
 */
public class AddTaskSwingWorker  extends SwingWorker<Class<Void>, Void>{
    private final Task task;
        FrameMainWindow.TableTaskModel model;
        public AddTaskSwingWorker(Task task, FrameMainWindow.TableTaskModel model) {
            this.task = task;
            this.model = model;
        }

    @Override
    protected Class<Void> doInBackground() throws Exception {
        TaskManager taskManager = new TaskManagerImpl();
        taskManager.setDataSource(FrameMainWindow.getDataSource());
        taskManager.createTask(task);       
        return Void.TYPE;
    }
    
    @Override
    protected void done() {
        super.done(); 
        model.reload();
    }
}
